Skip to content

Update CHANGELOG entry when npm version is ran instead of only through GitHub Actions workflow#7078

Merged
NickColley merged 4 commits into
mainfrom
npm-version-hook
May 21, 2026
Merged

Update CHANGELOG entry when npm version is ran instead of only through GitHub Actions workflow#7078
NickColley merged 4 commits into
mainfrom
npm-version-hook

Conversation

@NickColley
Copy link
Copy Markdown
Contributor

@NickColley NickColley commented May 20, 2026

Update the CHANGELOG entry using the "postversion" lifecycle hook which will execute after the npm version is completed.

If preversion, version, or postversion are in the scripts property of the package.json, they will be executed as part of running npm version.
The exact order of execution is as follows:

  1. Check to make sure the git working directory is clean before we get started. Your scripts may add files to the commit in future steps. This step is skipped if the --force flag is set.
  2. Run the preversion script. These scripts have access to the old version in package.json. A typical use would be running your full test suite before deploying. Any files you want added to the commit should be explicitly added using git add.
  3. Bump version in package.json as requested (patch, minor, major, etc).
  4. Run the version script. These scripts have access to the new version in package.json (so they can incorporate it into file headers in generated files for example). Again, scripts should explicitly add generated files to the commit using git add.
  5. Commit and tag.
    6. Run the postversion script. Use it to clean up the file system or automatically push the commit and/or tag.

https://docs.npmjs.com/cli/v11/commands/npm-version#description

Uses undocumented environment variables to get both the old and new
versions:
https://github.com/npm/cli/blob/c97b39b1e3436cd20a67ab5f4012a5f395c538b9/workspaces/libnpmversion/lib/version.js#L100-L103

Closes #7033

@NickColley NickColley requested a review from a team as a code owner May 20, 2026 13:29
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

📋 Stats

No changes to any distributed file sizes!


Action run for 07d026c

Comment thread bin/update-changelog.mjs
Comment thread .github/workflows/build-release.yml Outdated
Copy link
Copy Markdown
Contributor

@domoscargin domoscargin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - a few comments from me

Comment thread package-lock.json Outdated
Comment thread .github/workflows/build-release.yml
Comment thread bin/tsconfig.json
Comment thread package.json Outdated
Copy link
Copy Markdown
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script looks neat and good find about the env variables for the versions when npm invokes it 🙌🏻

I think Babel doesn't need updating, though, as it's not part of the process for running the script.

Comment thread bin/update-changelog.mjs
Comment thread babel.config.js Outdated
Comment thread packages/govuk-frontend/package.json Outdated
Update the CHANGELOG entry using the "postversion" lifecycle hook
which will execute after the `npm version` is completed.

> If preversion, version, or postversion are in the scripts property of the package.json, they will be executed as part of running npm version.
> The exact order of execution is as follows:
> 1. Check to make sure the git working directory is clean before we get started. Your scripts may add files to the commit in future steps. This step is skipped if the --force flag is set.
> 2. Run the preversion script. These scripts have access to the old version in package.json. A typical use would be running your full test suite before deploying. Any files you want added to the commit should be explicitly added using git add.
> 3. Bump version in package.json as requested (patch, minor, major, etc).
> 4. Run the version script. These scripts have access to the new version in package.json (so they can incorporate it into file headers in generated files for example). Again, scripts should explicitly add generated files to the commit using git add.
> 5. Commit and tag.
> 6. Run the postversion script. Use it to clean up the file system or automatically push the commit and/or tag.

https://docs.npmjs.com/cli/v11/commands/npm-version#description

Uses undocumented environment variables to get both the old and new
versions:
https://github.com/npm/cli/blob/c97b39b1e3436cd20a67ab5f4012a5f395c538b9/workspaces/libnpmversion/lib/version.js#L100-L103
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-7078 May 21, 2026 14:55 Inactive
@NickColley
Copy link
Copy Markdown
Contributor Author

Example run with all the existing changes:
https://github.com/alphagov/govuk-frontend/actions/runs/26234167352

Copy link
Copy Markdown
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to merge 🥳

@NickColley NickColley merged commit 5c245d3 into main May 21, 2026
51 checks passed
@NickColley NickColley deleted the npm-version-hook branch May 21, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the changelog as part of running npm version

4 participants